#include "CFont.h"

namespace DarkStorm2D {
namespace GraphicsCore {

const CError& CFont::LoadFromFile(const std::string & Filename)
{
	if (CSAllegroController::GetSingletonPtr()->GetInit(FLAG_ALLEGRO_FONT_ADDON))
	{
		m_Font = al_load_ttf_font(Filename.c_str(),m_Size,0);
	}
	else
	{
		if (CSAllegroController::GetSingletonPtr()->Init(FLAG_ALLEGRO_FONT_ADDON))
		{
			m_Font = al_load_ttf_font(Filename.c_str(),m_Size,0);
		}
	}
	if (NULL == m_Font)
		return CError(CError::TYPE_SYSTEM_ERROR,CError::FILE_LOAD);
	m_IsLoad = true;
	return CError();
}

const CError& CFont::LoadFromFile(const std::string & Filename, int Size, int Flags)
{
	if (CSAllegroController::GetSingletonPtr()->GetInit(FLAG_ALLEGRO_FONT_ADDON))
	{
		m_Font = al_load_ttf_font(Filename.c_str(),Size,Flags);
	}
	else
	{
		if (CSAllegroController::GetSingletonPtr()->Init(FLAG_ALLEGRO_FONT_ADDON))
		{
			if (CSAllegroController::GetSingletonPtr()->Init(FLAG_ALLEGRO_TTF_ADDON))
				m_Font = al_load_ttf_font(Filename.c_str(),Size,Flags);
		}
	}
	m_Size = Size;
	if (NULL == m_Font)
		return CError(CError::TYPE_SYSTEM_ERROR,CError::FILE_LOAD);
	m_IsLoad = true;
	return CError();
}


}
}